﻿using Coldairarrow.Util;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;

namespace Coldairarrow.Api.Controllers.UploadFile
{
    [Route("/PictureUpload/[controller]/[action]")]
    public class UploadFileController : BaseController
    {

        readonly IConfiguration _configuration;
        public UploadFileController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        #region 保存
        /// <summary>
        /// 个人中心图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult PersonalSaveImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  
                    var t = Guid.NewGuid().ToString();
                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/Personal/{t}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }
        /// <summary>
        /// 商品图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GoodsSaveImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  
                    var t = Guid.NewGuid().ToString();
                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/Goods/{t}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }
        /// <summary>
        /// 供货商图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SupplierSaveImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  
                    var t = Guid.NewGuid().ToString();
                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/Supplier/{t}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }
        /// <summary>
        /// 规格图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult ParameteSaveImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  
                    var t = Guid.NewGuid().ToString();
                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/Paramete/{t}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }
        /// <summary>
        /// 商品分类ICON图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GoodsTypeSaveImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  
                    var t = Guid.NewGuid().ToString();
                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/GoodsType/{t}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }
        /// <summary>
        /// 商品分类ICON图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult CompanySaveImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  
                    var t = Guid.NewGuid().ToString();
                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/Company/{t}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }
        /// <summary>
        /// 用户图像上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult UserImgSaveImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  
                    var t = Guid.NewGuid().ToString();
                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/UserImg/{t}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }
        #endregion

        #region 材料图片上传

        /// <summary>
        /// 材料图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SaveMaterialImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  
                    var t = Guid.NewGuid().ToString();
                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/Material/Image/{t}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }

        #endregion

        #region 加工厂图片上传

        /// <summary>
        /// 加工厂图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SaveFactoryImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  
                    var t = Guid.NewGuid().ToString();
                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/Factory/Image/{t}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }

        #endregion

        #region 叶片图片上传

        /// <summary>
        /// 叶片图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SaveLeafBladeImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  
                    var t = Guid.NewGuid().ToString();
                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/LeafBlade/Image/{t}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }

        #endregion

        #region 工人图片上传

        /// <summary>
        /// 工人图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SaveWorkerImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  
                    var t = Guid.NewGuid().ToString();
                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/Worker/Image/{t}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }

        #endregion

        #region 保存
        /// <summary>
        /// 保存图片
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SaveContentImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  
                    var t = Guid.NewGuid().ToString();
                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/Image/Content/{t}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }
        /// <summary>
        /// 保存图片
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SavecommentImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  
                    var t = Guid.NewGuid().ToString();
                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/comment/image/{t }/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }

        #endregion

        #region 投票图片上传
        /// <summary>
        /// 投票图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SaveVoteImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  

                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/Image/Vote/{DateTime.Now.ToString("yyyyMMdd")}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }

        #endregion

        #region 模板图片保存
        /// <summary>
        /// 模板图片保存
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [DisableRequestSizeLimit]
        public ActionResult SaveTempImg()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  

                    for (int i = 0; i < _file.Count; i++)
                    {
                        if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                        {
                            path = $"/Upload/Image/Template/{DateTime.Now.ToString("yyyyMMdd")}/{_file[i].FileName}";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[i].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[i].FileName,
                                data = url
                            };
                        }
                    }
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }
        #endregion

        #region 保存文档
        /// <summary>
        /// 保存文档(支持Word(.doc,.docx)\Excel(.xls,.xlsx)\PPT(.ppt,.pptx)\Pdf(.pdf)\TXT(.txt)部分通用格式)
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [DisableRequestSizeLimit]
        public ActionResult SaveTheFile()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  

                    //for (int i = 0; i < _file.Count; i++)
                    //{
                        if (_tp.ToLower() == ".doc" || _tp.ToLower() == ".docx" || _tp.ToLower() == ".xls" || _tp.ToLower() == ".exe" || _tp.ToLower() == ".xlsx" || _tp.ToLower() == ".pdf" || _tp.ToLower() == ".ppt" || _tp.ToLower() == ".pptx")
                        {
                            path = $"/Upload/Image/Base_Company/{DateTime.Now.ToString("yyyyMMdd")}/{_file[0].FileName.Replace(_tp,"") + DateTime.Now.ToString("yyyyMMddHHmmss")+ _tp }";
                            string physicPath = GetAbsolutePath($"~{path}");
                            string dir = Path.GetDirectoryName(physicPath);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                            {
                                _file[0].CopyTo(fs);
                            }

                            string url = path;
                            res = new
                            {
                                Success = true,
                                message = _file[0].FileName.Replace(_tp, ""),
                                data = url
                            };
                        }
                    //}
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }
        #endregion

        #region 保存音频
        /// <summary>
        /// 保存音频（支持".mp3"和".wav"格式）
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [DisableRequestSizeLimit]
        public ActionResult SaveVoice()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  

                    //for (int i = 0; i < _file.Count; i++)
                    //{
                    if (_tp.ToLower() == ".mp3" || _tp.ToLower() == ".wav" )
                    {
                        path = $"/Upload/Voice/Base_Company/{DateTime.Now.ToString("yyyyMMdd")}/{_file[0].FileName.Replace(_tp, "") + DateTime.Now.ToString("yyyyMMddHHmmss") + _tp}";
                        string physicPath = GetAbsolutePath($"~{path}");
                        string dir = Path.GetDirectoryName(physicPath);
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                        {
                            _file[0].CopyTo(fs);
                        }

                        string url = path;
                        res = new
                        {
                            Success = true,
                            message = _file[0].FileName.Replace(_tp, ""),
                            data = url
                        };
                    }
                    //}
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }
        #endregion

        #region 保存视频
        /// <summary>
        /// 保存音频（支持".mp4"、".avi"、".flv"、".mkv"和".3gp"格式）
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [DisableRequestSizeLimit]
        public ActionResult SaveVideo()
        {
            var _file = Request.Form.Files;//客户端上传的文件 
            var res = new object();
            try
            {
                if (_file.Count > 0)
                {
                    string path = "";
                    long size = _file[0].Length;//文件大小                       
                    string type = _file[0].ContentType;//文件类型                       
                    string name = _file[0].FileName;//文件名                      
                    string _tp = System.IO.Path.GetExtension(name); //文件格式  

                    //for (int i = 0; i < _file.Count; i++)
                    //{
                    if (_tp.ToLower() == ".mp4" || _tp.ToLower() == ".avi" || _tp.ToLower() == ".flv" || _tp.ToLower() == ".mkv" || _tp.ToLower() == ".3gp")
                    {
                        path = $"/Upload/Video/Base_Company/{DateTime.Now.ToString("yyyyMMdd")}/{_file[0].FileName.Replace(_tp, "") + DateTime.Now.ToString("yyyyMMddHHmmss") + _tp}";
                        string physicPath = GetAbsolutePath($"~{path}");
                        string dir = Path.GetDirectoryName(physicPath);
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        using (FileStream fs = new FileStream(physicPath, FileMode.Create))
                        {
                            _file[0].CopyTo(fs);
                        }

                        string url = path;
                        res = new
                        {
                            Success = true,
                            message = _file[0].FileName.Replace(_tp, ""),
                            data = url
                        };
                    }
                    //}
                }
                else
                {
                    res = new { success = false, message = "文件不能为空！", Data = new object() };
                }
            }
            catch (Exception ex)
            {
                res = new { success = false, message = ex.Message, Data = new object() };
            }

            return JsonContent(res.ToJson());
        }
        #endregion

    }
}